<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
  		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>修改密码</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
		<script src="../../../../src/static/jquery.js"></script>

	</head>
	<body>
		<div class="layui-tab page-content-wrap">
		  <ul class="layui-tab-title">
		    <li class="layui-this">修改密码</li>
		  </ul>
		  <div class="layui-tab-content">
		    <div class="layui-tab-item layui-show">
				<form class="layui-form" v style="width: 90%;padding-top: 20px;">
					<div class="layui-form-item">
						<label class="layui-form-label">手机号码：</label>
						<div class="layui-input-block">
							<input type="text" id="phone"  disabled  maxlength="11" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">旧密码：</label>
						<div class="layui-input-block">
							<input type="password" id="odpassword" required lay-verify="required" placeholder="请输入密码(密码长度6~10)"  maxlength="10"  autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">新密码：</label>
						<div class="layui-input-block">
							<input type="password" id="xpassword" required lay-verify="required" placeholder="请输入密码(密码长度6~10)" maxlength="10" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">重复密码：</label>
						<div class="layui-input-block">
							<input type="password" id="xpassword1" required lay-verify="required" placeholder="请输入密码(密码长度6~10)" maxlength="10" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" type="button" onclick="tijiao()" >立即提交</button>
						</div>
					</div>
				</form>
		    </div>
		  </div>
		</div>
	<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script>
		//Demo
		layui.use(['form','element'], function(){
		  var form = layui.form();
		});

        $.ajax(
            {
                url: '/api/findPhone',
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    var phn = data.phone.substr(0,3)+"****"+data.phone.substr(7);
                      	$("#phone").val(phn);
                },
                error: function (error) {
                    //请求失败  获取的报错信息
                    console.log(error);
                }
            }
        );

		function tijiao() {
			var flg = yanzheng();
			if(flg == true){
                flg = cxwp();
                if(flg == true){
                    var phone = $("#phone").val();
                    var odpassword = $("#odpassword").val();
                    var xpassword = $("#xpassword").val();
                    $.ajax(
                        {
                            url: '/api/updateTicketShop',
                            data: {
                                phone: phone,
                                odpassword: odpassword,
                                xpassword: xpassword
                            },
                            type: 'GET',
                            dataType: 'json',
                            success: function (data) {
                                alert(data.msg);
                                window.location.reload();
                            },
                            error: function (error) {
                                //请求失败  获取的报错信息
                                console.log(error);
                            }
                        }
                    );
				}
			}
        }
        function yanzheng(){
            if( $("#phone").val().length !== 11){
                layer.msg("请输入正确格式的手机号！");
                return false;
            }else if($("#odpassword").val()==null ||  $("#odpassword").val() ==""){
                layer.msg("旧密码不能为空！");
                return false;
			}else if($("#xpassword").val()==null ||  $("#xpassword").val() ==""){
                layer.msg("新密码不能为空！");
                return false;
            }else if($("#xpassword1").val()==null ||  $("#xpassword1").val() ==""){
                layer.msg("重复密码不能为空！");
                return false;
            }
            return true;
		}
		function cxwp() {
            if($("#odpassword").val().length<6){
                layer.msg("旧密码必须为6~10位！");
                return false;
			}else if($("#xpassword").val()<6){
                layer.msg("新密码必须为6~10位！");
                return false;
			}else if($("#xpassword1").val()<6){
                layer.msg("重复密码必须为6~10位！");
                return false;
			} else if($("#xpassword").val() !== $("#xpassword1").val()){
                layer.msg("新密码与重复密码不一致！");
                return false;
			}
			return true;
        }
	</script>
	</body>
</html>